package com.web.controller;

import com.web.pojo.MessageWall;
import com.web.service.impl.MessageWallService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class InteractionController {

    @RequestMapping("/MessageWallAll")
    @ResponseBody
    public List<MessageWall> save0() {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");
        MessageWallService messageWallService = context.getBean("messageWallService", MessageWallService.class);
        List<MessageWall> data = messageWallService.findAllMessage();
        return data;
    }

    @RequestMapping("/InsertMessage")
    @ResponseBody
    public List<MessageWall> save1(MessageWall messageWall) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");
        MessageWallService messageWallService = context.getBean("messageWallService", MessageWallService.class);
        int i = messageWallService.InsertMessage(messageWall);
        System.out.println(messageWall);
        if (i == 1) {
            return messageWallService.findAllMessage();
        } else {
            return null;
        }
    }

    @RequestMapping("/Deletemessage")
    @ResponseBody
    public List<MessageWall> save2(int id) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");
        MessageWallService messageWallService = context.getBean("messageWallService", MessageWallService.class);
        int i = messageWallService.DeleteMessage(id);
        if (i == 1) {
            return messageWallService.findAllMessage();
        } else {
            return null;
        }
    }
}